<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>产品信息列表</title>
    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="css/user.css">
    <script src="js/user.js"></script>
</head>

<body>

<div class="container-fluid">
    <div class="row">

        <div class="col-sm-12" id="right">
            <ol class="breadcrumb">
                <li class="active">菜单
                </li>
                <li class="active">编辑产品信息
                </li>
            </ol>

            <div class="panel panel-default">
                <div class="panel-heading">
                    填写产品信息
                </div>
                <div class="panel-body">
                    <%
                        int i = 0;
                        if (request.getParameter("id") != null) {
                            String I = request.getParameter("id");
                            i = Integer.parseInt(I);
                        }
                        String productCode = "";
                        String productName = "";
                        String productSize = "";
                        String batch = "";
                        String worker = "";
                        String processingMethod = "";
                        String processingDate = "";
                        String workshop = "";

                        Connection conn = (Connection)session.getAttribute("Connection");
                        String sql = "select * from product where id=" + i;
                        PreparedStatement preparedStatement = conn.prepareStatement(sql);
                        ResultSet rs = preparedStatement.executeQuery();
                        rs.next();
                        try {
                            if(rs.getString("productCode")!=null)
                                productCode = rs.getString("productCode");
                            if(rs.getString("productName")!=null)
                                productName = rs.getString("productName");
                            if(rs.getString("productSize")!=null)
                                productSize= rs.getString("productSize");
                            if(rs.getString("batch")!=null)
                                batch = rs.getString("batch");
                            if(rs.getString("worker")!=null)
                                worker = rs.getString("worker");
                            if(rs.getString("processingMethod")!=null)
                                processingMethod = rs.getString("processingMethod");
                            if(rs.getString("processingDate")!=null)
                                processingDate = rs.getString("processingDate");
                            if(rs.getString("workshop")!=null)
                                workshop = rs.getString("workshop");
                        } catch (SQLException e) {

                        }
                    %>
                    <form role="form" class="form-horizontal" action="<%if(i==0)out.print("product_add_do.jsp");else out.print("product_edit_do.jsp?id="+i);%>" method="post">
                        <div class="form-group">
                            <label  class="col-sm-2 control-label">产品身份码<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="productCode" name="productCode"
                                       value="<%=productCode%>"
                                       placeholder="请输入产品身份码">
                                <span id="productCodeError" class="errortext">
                                   <%
                                       productCode = request.getParameter("productCode");
                                       if (productCode != null) {
                                           if (productCode == "") {
                                               out.println("产品身份码不能为空");
                                           } else if (productCode.length() != 6) {
                                               out.println("格式错误,长度应为6个数字");
                                           }
                                       }
                                   %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">产品名称<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="productName" name="productName"
                                       value="<%=productName%>"
                                       placeholder="请输入产品名称">
                                <span id="productNameError" class="errortext">
                                  <%
                                      productName = request.getParameter("productName");
                                      if (productName != null) {
                                          if (productName == "") {
                                              out.println("产品名称不能为空");
                                          } else if (productName.length() > 6) {
                                              out.println("产品名称不得超过6个字符");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">外观尺寸<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input class="form-control" id="productSize" name="productSize"placeholder="请输入尺寸大小" value="<%=productSize%>">
                                <span id="productSizeError" class="errortext">
                                  <%
                                      productSize = request.getParameter("productSize");
                                      if (productSize != null) {
                                          if (productSize == "") {
                                              out.println("外观尺寸不能为空");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">批次<sup
                                    class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="batch" name="batch"
                                       value="<%=batch%>"
                                       placeholder="请输入批次">
                                <span id="batchError" class="batchtext">
                                 <%
                                     batch = request.getParameter("batch");
                                     if (productSize != null) {
                                         if (!batch.matches("\\d+")) {
                                             out.println("批次应为数字");
                                         }
                                     }
                                 %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">加工人员<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="worker" name="worker"
                                       value="<%=worker%>"
                                       placeholder="请输入加工人员">
                                <span id="workerError" class="errortext">
                                  <%
                                      worker = request.getParameter("worker");
                                      if (worker != null) {
                                          if (worker == "") {
                                              out.println("加工人员不能为空");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">加工方法</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="processingMethod" name="processingMethod"
                                       value="<%=processingMethod%>"
                                       placeholder="请输入加工方法">
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-2 control-label">加工时间<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <input type="date" class="form-control" id="processingDate" name="processingDate"
                                       value="<%=processingDate%>"
                                       placeholder="请输入加工时间">
                                <span id="processingDateError" class="errortext">
                                  <%
                                      processingDate = request.getParameter("processingDate");
                                      if (processingDate != null) {
                                          if (processingDate == "") {
                                              out.println("加工时间不能为空");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">加工车间<sup class="text_sup">*</sup></label>
                            <div class="col-sm-8">
                                <select class="form-control" id="workshop" name="workshop">
                                    <option value="">请选择</option>
                                    <option value="表面处理车间" <% if (workshop.equals("表面处理车间"))
                                        out.print("selected"); %> >表面处理车间
                                    </option>
                                    <option value="锻压车间" <% if (workshop.equals("锻压车间")) out.print("selected"); %> >
                                        锻压车间
                                    </option>
                                    <option value="组装车间" <% if (workshop.equals("组装车间")) out.print("selected"); %> >
                                        组装车间
                                    </option>
                                    <option value="质检车间" <% if (workshop.equals("质检车间")) out.print("selected"); %> >
                                        质检车间
                                    </option>
                                    <option value="机加车间" <% if (workshop.equals("机加车间")) out.print("selected"); %> >
                                        机加车间
                                    </option>
                                </select>
                                <span id="workshopError" class="errortext">
                                  <%
                                      workshop = request.getParameter("workshop");
                                      if (workshop != null) {
                                          if (workshop == "") {
                                              out.println("加工车间不能为空");
                                          }
                                      }
                                  %>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-primary">保存</button>
                                <button type="reset" class="btn btn-default">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

</body>

</html>
